﻿using System.Collections.Generic;
using System.Linq;
using UnityEngine;


namespace BackpackSystem
{
    /// <summary>
    /// 
    /// </summary>
    public class InventoryAsset
    {
        /// <summary>
        /// 
        /// </summary>
        public static Dictionary<ItemType, ItemBase> ItemsTemplate;

        /// <summary>
        /// 
        /// </summary>
        public static void Load()
        {
            ItemsTemplate = new Dictionary<ItemType, ItemBase>();

            ItemsTemplate.Add(ItemType.Cube, new ItemCube().InitItem());
            ItemsTemplate.Add(ItemType.Capsule, new ItemCapsule().InitItem());
            ItemsTemplate.Add(ItemType.Cylinder, new ItemCylinder().InitItem());
            ItemsTemplate.Add(ItemType.Sphere, new ItemSphere().InitItem());
        }

        /// <summary>
        /// 
        /// </summary>
        public static bool TryGetItem(ItemType itemType, out ItemBase output) 
        {
            bool isGet = ItemsTemplate.TryGetValue(itemType, out output);
            if (!isGet)
            {
                Debug.LogError($"InventoryAsset | {itemType} 不存在");
                output = null;
                return false;
            }
        

            return true;
        }

        /// <summary>
        /// 
        /// </summary>
        public static ItemBase GetItem(Sprite sprite)
        {
            return ItemsTemplate.ToList().Find(e => e.Value.Icon == sprite).Value;
        }
    }
}
